public class Test11 {
    public static void main(String[] args) {
        //普通代码块
        {
            //局部变量
        int a = 10;
            System.out.println(a);
    }
        //System.out.println(a);
            Student.setClassRoom("109");
    Student s1 = new Student(19,"谢沐彦");
        System.out.println(s1.getName()+s1.getAge()+Student.getClassRoom());//由于被private封装，所以无法被直接调用
        Student s2 = new Student();
        System.out.println(s2.getName()+s2.getAge()+Student.getClassRoom());
        System.out.println(Student.count);

    }
}
class Student{
    //成员变量：定义在类的内部，方法的外部
    private String name;
    private int age;
    private String sex;
    //静态成员变量
    private static String classRoom;
    //实例代码块
    {
        this.name = "蔡徐坤";
        this.age = 15;
        this.sex = "男";
    }
    //静态代码块
    static
    {
     count = 0;
    }
    public static void setClassRoom(String classRoom) {
        Student.classRoom = classRoom;
    }

    public static String getClassRoom() {
        return classRoom;
    }

    //静态成员方法
    static int count = 0;
    public static void count(){
        count++;
        //show();//静态方法内部不能直接调用非静态成员方法，也不能直接调用非静态成员属性
        Student student = new Student();
        student.show();
    }

    @Override
    //直接调用toString方法对对象进行输出
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                '}';
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    //成员方法
    public void eat(){
        System.out.println(this.name + "在吃");
        this.show();
    }
public void show(){
    System.out.println("姓名" + this.name + "年龄" + this.age);
}
    public void setName(String name) {
        this.name = name;
    }
    public Student(int age,String name){
        count++;
        //带参的构造方法
        System.out.println("带参的构造方法");
        this.name = name;
        this.age = age;

    }
    //构造方法:对对象成员的初始化
    public Student(){
//        this(19,"cc");          //this(),调用当前类中的其他构造方法
        System.out.println("不带参的构造方法");
    }

    public Student(String name, int age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public static void main(String[] args) {
//        Student S1 = new Student();
//        S1.name = "冼泽厚";
//        S1.eat();
        Student S3 = new Student();
        System.out.println(S3);

//        Student S2 = new Student();
//        S2.setName("谢沐彦");  //调用set方法赋值
//        S2.eat();
    }
}
